<?php
    session_start();
    if(!isset($_SESSION['username'])){
                header("Location: index.php");
                $_SESSION['log']=1;
    }
    else{


    if(isset($_POST['add'])){
        $i=0;
        $stored_prod;
        foreach($_SESSION['products'] as $p){
            if($_POST["check_$i"]=='ON'){
                //echo $p['name']." ".$p['sku']."<br>";
                $stored_prod[$i]=$p;
                $i++;
            }
        }
        $_SESSION['stored_prod']=$stored_prod;
        $URL="priceSet.php";

        header ("Location: $URL");
        //echo "Added!";

    }
    else{ ?>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
@import url("style.css");
</style>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/ui.core.js"></script>
<script type="text/javascript" src="js/ui.accordion.js"></script>
<script type="text/javascript" src="js/jquery.easing.js"></script>
<script type="text/javascript">
    $(document).ready(function(){

        $("#displaylist").accordion({
            header: '.itemName',
            animated: 'easeslide',
            navigation: false
        });
    });
</script>
</head>
<body>
        <?php
        echo '<form action="display.php" method="POST">';
        include 'config.php';
        $proxy = new SoapClient($config['SOAPLocation']);
        $sessionId = $proxy->login($config['SOAPUser'],$config['SOAPKey']);
        $prod = $proxy->call($sessionId,'catalog_product.list', 'default');
        $_SESSION['products']=$prod;
        $proxy->endSession($sessionId);
        $i=0;
        echo "<ul id='displaylist'>";
        foreach($prod as $p){
            echo "<li>";
            echo "<a class='itemName' href='#'>{$p['name']}</a>";
            echo "<div class='item'>";
            echo "<ul><li class='select'><input type='checkbox' name='check_$i' value='ON' /></li>";
            echo "<li class='name'>{$p['name']}</li>";
            echo "<li class='sku'>{$p['sku']}</li></ul></div></li>";

            $i++;
        }
        echo "</ul>";
        echo '<input type="submit" value="Add these items to Store" name="add" />';
        echo '</form>';
    }
    
    
?>
</body>
</html>
<?php } ?>